package com.softcomputer.rpt.client;

import com.softcomputer.rpt.entities.ExCourse;
import java.io.File;
import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import javax.xml.rpc.ServiceFactory;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.ws.Service;
import org.xml.sax.SAXException;
import javax.xml.rpc.ServiceException;

@XmlSeeAlso(ExCourse.class)
public class User {

    private Marshaller marshaller;
    private static Unmarshaller unmarshaller;
    private static JAXBContext jaxbContext;
    private static SchemaFactory schemaFactory;
    private static ExCourse course;
    private static File file;

    public static void main(String[] args) throws MalformedURLException, FileNotFoundException, ServiceException {
        URL url = new URL("http://ipsedin:8080/EchoBeanService/EchoBean?wsdl");
        QName qname = new QName(
                "http://ipsedin:8080/EchoBeanService",
                "EchoBeanService");

        Service remote = Service.create(url, );
        file = new File("courses.xml");
        try {
            jaxbContext = JAXBContext.newInstance(User.class);
            unmarshaller = jaxbContext.createUnmarshaller();

            schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            Schema schema = schemaFactory.newSchema(new File("schema.xsd"));
            unmarshaller.setSchema(schema);

        } catch (JAXBException e) {
            System.out.println("Jaxb exception: " + e.getMessage());
        } catch (SAXException e) {
            System.out.println("SAX exception: " + e.getMessage());
        }

        try {
            course = (ExCourse) unmarshaller.unmarshal(file);
        } catch (JAXBException e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }

        System.out.println(course);
        
        xmlService.processXml(course);
    }
}
